package com.chen;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;


/**
 * JDK 自带的 Timer
 */
public class JdkTaskDemo {

    public static void main(String[] args) {
        //创建定时类
        Timer timer=new Timer();
        //创建任务类
        TimerTask task=new TimerTask() {
            @Override
            public void run() {
                System.out.println("定时任务执行了..."+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            }
        };

        //执行定时任务
        timer.schedule(task,0,2000);
    }
}
